package com.guli.order.listener;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.guli.common.constant.MqConstant;
import com.guli.common.utils.Query;
import com.guli.common.utils.R;
import com.guli.order.entity.OrderEntity;
import com.guli.order.feign.WmsFeignService;
import com.guli.order.service.OrderService;
import com.guli.order.vo.WareOrderTaskVo;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import springfox.documentation.spring.web.json.Json;

import java.io.IOException;
import java.time.LocalDateTime;


/**
 * @Author zzb
 * @Date 2024/4/21 23:17
 * @Version 1.0
 */
@RabbitListener(queues = MqConstant.ORDER_CLOSE_QUEUE)
@Component
@Slf4j
public class OrderCloseListener {
    @Autowired
    WmsFeignService wmsFeignService;
    @Autowired
    OrderService orderService;

    @RabbitHandler
    public void handleCloseOrder(OrderEntity orderEntity, Message message, Channel channel) {
        log.info("{} => {} => 订单进入取消", LocalDateTime.now(), orderEntity.getOrderSn());
        orderService.closeOrder(orderEntity);
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException e) {
            try {
                channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
            } catch (IOException ex) {
                log.info(ex.getMessage());
            }
        }
    }
}
